<template>
    <div>
        <el-form ref="editForm" :rules="rules" :model="editForm" label-width="120px">
          <el-form-item label="日利润" prop="day_income">
            <el-input v-model="editForm.day_income"></el-input>
          </el-form-item>
          <el-form-item label="月利润" prop="month_income">
            <el-input v-model="editForm.month_income"></el-input>
          </el-form-item>
          <el-form-item label="金额上限" prop="money_up">
            <el-input v-model="editForm.money_up"></el-input>
          </el-form-item>
           <el-form-item label="金额下限" prop="money_down">
            <el-input v-model="editForm.money_down"></el-input>
          </el-form-item>
          <el-form-item label="开始时间" prop="sell_start_time">

                <el-date-picker
                    v-model="editForm.sell_start_time"
                     type="date"
                    placeholder="开始日期时间"
                 >
                  </el-date-picker>
            </el-form-item>

             <el-form-item label="结束时间" prop="sell_end_time">
                <el-date-picker
                    v-model="editForm.sell_end_time"
                     type="date"
                    placeholder="结束日期时间"
                  >
                  </el-date-picker>

          </el-form-item>
          <el-form-item label="周期" prop="period">
            <el-input v-model="editForm.period" ></el-input>
          </el-form-item>
          <el-form-item label="直推奖励比例" prop="zhitui_income">
            <el-input v-model="editForm.zhitui_income"></el-input>
          </el-form-item>
           <el-form-item align="center">
           <el-button type="success" @click="submitForm('editForm')">添加</el-button>
           </el-form-item>
    </el-form>

    </div>
</template>

<script>
    export default{
        data(){
            return{
                editForm:{
                    commodity_id:'',
                    money_up:'',
                    money_down:'',
                    day_income:'',
                    month_income:'',
                    sell_start_time:'',
                    sell_end_time:'',
                    period:'',
                    zhitui_income:''
                },
                rules:{
                     money_up:[
                         { required: true, message: '请输入金额上限', trigger: 'blur' }
                     ],
                     money_down:[
                         { required: true, message: '请输入金额下限', trigger: 'blur' }
                     ],
                     day_income:[
                         { required: true, message: '请输入日利润', trigger: 'blur' }
                     ],
                     month_income:[
                         { required: true, message: '请输入月利润', trigger: 'blur' }
                     ],
                     sell_start_time:[
                         {required: true, message: '请输入销售开始时间', trigger: 'change' }
                     ],
                     sell_end_time:[
                         {required: true, message: '请输入销售结束时间', trigger: 'change' }
                     ],
                     period:[
                         { required: true, message: '请输入周期', trigger: 'blur' }
                     ],
                     zhitui_income:[
                         { required: true, message: '请输入直推收益', trigger: 'blur' }
                     ],
                }

            }
        },
        methods:{
            submitForm(editForm){
                        let d = new Date(this.editForm.sell_start_time)
                        this.editForm.sell_start_time = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
                        let f = new Date(this.editForm.sell_end_time)
                        this.editForm.sell_end_time = f.getFullYear() + '-' + (f.getMonth() + 1) + '-' + f.getDate() + ' ' + f.getHours() + ':' + f.getMinutes() + ':' + f.getSeconds();
                this.$refs[editForm].validate((valid) => {
                    if(valid){
                        this.$post_('trade/commodity/save',this.editForm,(res) => {

                                     if(res.code ==0){
                                        this.$message({
                                            message:"添加成功",
                                             type: 'success'
                                        })
                                     }

                             })
                    }else{
                            console.log('error submit!!');
                            return false;
                         }

                    // console.log(this.editForm)

                })
            }
        }
    }
</script>

<style>
</style>
